<template>
    <div>
        手机号：<input type="text" placeholder="手机号" v-model="phone"> <br>
        密码：<input type="text" v-model="password">
        <button @click="registry">注册</button>
    </div>
</template>

<script>
import request from '../util/request'
export default {
    data(){
        return {
            phone:'',
            password:''
        }
    },
    methods:{
        registry(){
            if(this.password && /^\d{11}$/.test(this.phone)){
                //注册接口
                request.post('/api/registry',{phone:this.phone,password:this.password}).then(res => {
                    if(res.code === 1){
                        console.log("注册成功");
                        this.$router.push('/login');
                    }else{
                        console.log("注册失败")
                    }
                })
            }else{
                alert("参数有误")
            }
        }
    }
}
</script>